$(function () {
    container.off('click');
    function getMyEquipmentStorageByName(page) {
        axios({
            url:url,
            params:{
                "async":true,
                "page":page,
                "equipmentName":$("#searchName").val()
            }
        }).then(function (response) {
            $("#mainContainer").html(response.data);
        }).catch(function (error) {
            toastr.error("error!");
        });
    }
    //分页
    $.tbpage("#mainContainer",function (page) {
        getMyEquipmentStorageByName(page);
    });

    //搜索
    $("#searchNameBtn").click(function () {
        getMyEquipmentStorageByName(0);
    });


    // 撤销待审核的器材入库
    container.on("click","#undo-equipmentStorage", function () {
        // 获取 CSRF Token
        var csrfToken = $("meta[name='_csrf']").attr("content");
        axios({
            method:'DELETE',
            url: "/equipmentStorage/"+ $(this).attr("teacherNumber")+'/revocation/'+$(this).attr("equipmentStorageId"),
            headers:{'X-CSRF-TOKEN':csrfToken}
        }).then(function (response) {
            if (response.data.success) {
                // 从新刷新主界面
                getMyEquipmentStorageByName(0);
                toastr.success(response.data.message);
            } else {
                toastr.error(response.data.message);
            }
        }).catch(function (error) {
            toastr.error("error!");
        });
    });

    // 完成通过的器材入库
    container.on("click","#ok-equipmentStorage", function () {
        // 获取 CSRF Token
        var csrfToken = $("meta[name='_csrf']").attr("content");
        axios({
            method:'POST',
            url: "/equipmentStorage/"+ $(this).attr("teacherNumber")+'/achieve/'+$(this).attr("equipmentStorageId"),
            headers:{'X-CSRF-TOKEN':csrfToken}
        }).then(function (response) {
            if (response.data.success) {
                // 从新刷新主界面
                getMyEquipmentStorageByName(0);
                toastr.success(response.data.message);
            } else {
                toastr.error(response.data.message);
            }
        }).catch(function (error) {
            toastr.error("error!");
        });
    });

});